# -*- coding: utf-8 -*-
"""
Created on Tue Jun  5 21:16:41 2018

@author: Administrator
"""
#%%

from agilepipe.spine import AgilePipe

#%%
#the code below is used to process the T1 image
modality = '_T1'   #the image modality in the original_dirpath   '_T1' '_BOLD' '_PET'  '_PET'
manipulate_methods = { 'Spm_coregister_SC':{},
                      'Spm_segment_SS':{}
                      }
#dirpath 也是一个dict，其keys与manipulate_methods完全相同，但元素是对应处理方法所生成的文件夹的名字。
dirpath_dict = {'original_dirpath':[],
                     #用来存放其实的文件。
                     'Spm_coregister_SC':[],
                     'Spm_segment_SS':[]
                    }

#agile_pipe()用ccs处理BOLD的测试代码
original_dirpath = r'/media/root/Elements4/XuanWu_last/PET_processing/T1'
#the first element of dirpath_list is very important which is used as reference image when coregister PET to T1
dirpath_list = [r'/media/root/Elements4/XuanWu_last/PET_processing/PET','',''] #即使没有用也要赋值，否则会报错
dirpath_dict = dirpath_dict
manipulate_methods = manipulate_methods
parallel_core = 0.7
AgilePipe(modality,original_dirpath,dirpath_list,dirpath_dict,manipulate_methods,parallel_core)


#%%
#the code below is used to process the PET image
modality = '_PET'     #'_T1' '_BOLD' '_PET'  '_PET'
manipulate_methods = { 'Spm_normalize_SN':{},
                      'Spm_reslice_SR':{}
                      }
#dirpath 也是一个dict，其keys与manipulate_methods完全相同，但元素是对应处理方法所生成的文件夹的名字。
dirpath_dict = {'original_dirpath':[],
                     #用来存放其实的文件。
                     'Spm_normalize_SN':[],
                     'Spm_reslice_SR':[],
                    }

#agile_pipe()用ccs处理BOLD的测试代码
original_dirpath = r'/media/root/Elements4/XuanWu_last/PET_processing/PET'
#the first element of dirpath_list is very important which is used as deformation field 
#the second element of dirpath_list can be used in the reslice processing as the "Image Defining Space" filepath
dirpath_list = [r'/media/root/Elements4/XuanWu_last/PET_processing/T1_SC_SS','/root/Documents/BrainMask_05_61x73x61.nii',''] #即使没有用也要赋值，否则会报错
dirpath_dict = dirpath_dict
manipulate_methods = manipulate_methods
parallel_core = 0.7
AgilePipe(modality,original_dirpath,dirpath_list,dirpath_dict,manipulate_methods,parallel_core)


#%%
#perform partial volume correction

from agilepipe.process.petpvc import Petpvc

input_dirpath = '/media/root/Elements4/XuanWu_last/PET_processing/PET_SN_SR'
mask_dirpath = ''
algorithm_str = 'RBV'
fwhm_list = [6,6,6]
output_dirpath = '/media/root/Elements4/XuanWu_last/PET_processing/petpvc'

Petpvc([input_dirpath, mask_dirpath, algorithm_str, fwhm_list, output_dirpath])


#%%
#make mask before Z_standardize

from agilepipe.process import  Create_groupmask

source_dirpath = r'/media/root/Elements4/XuanWu_last/PET_processing/PET_SN_SR_del-subj24'
mnimask_filepath = r'/root/Documents/BrainMask_05_61x73x61.nii'
great_groupmask = Create_groupmask([source_dirpath,mnimask_filepath])


#%%
#perform Z_standardiz

from agilepipe.process import Z_standardize #,Mean_division

previous_dirpath = r'/media/root/Elements4/XuanWu_last/PET_processing/PET_SN_SR_del-subj24'
mask_filepath = r'/media/root/Elements4/XuanWu_last/mask/GM_mask/T1_SC_SS_GM_SN_SR_mean_threshold-0.5/T1_SC_SS_GM_SN_SR_mean_threshold-0.5.nii'
present_dirpath = r'/media/root/Elements4/XuanWu_last/PET_processing/PET_SN_SR_del-subj24_z'

Z_standardize([previous_dirpath,mask_filepath,present_dirpath])


#%%